using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class includes_LoginContentPage : System.Web.UI.UserControl
{
    protected string UserType;
    protected void Page_Load(object sender, EventArgs e)
    {
        string pageName = Request.Url.AbsolutePath.Substring(Request.Url.AbsolutePath.LastIndexOf("/"), (Request.Url.AbsolutePath.Length - Request.Url.AbsolutePath.LastIndexOf("/")));
        if (pageName.Trim().ToUpper() == "/doctorLogin.aspx".ToUpper())
        {
            UserType = "Doctor";
            rbtnlDoctorType.SelectedIndex = 0;
        }
        else if (pageName.Trim().ToUpper() == "/dentistLogin.aspx".ToUpper())
        {
            UserType = "Dentist";
            rbtnlDoctorType.SelectedIndex = 1;
        }    
    }

    /// <summary>
    /// Store the login information in session variables
    /// </summary>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        if (Request.QueryString["Id"] != null)
        {
            Session["FriendReqSenderID"] =Convert.ToString(Request.QueryString["Id"]);
            Session["FriendReqSenderType"] = Convert.ToString(Request.QueryString["type"]);
            Session["AcceptRequest"] = "AcceptReq";
           // Session["userID"] = Convert.ToString(Request.QueryString["recieverId"]);
            Session["StrEmailToID"] = Convert.ToString(Request.QueryString["Id"]);
            if ((Request.QueryString["type"] == "Doctor"))
            {
                Session["ReceiverType"] = 2;
              // Session["DoctorType"] = "Doctor";
              // Session["isDoctorOrDentist"] = "Doctor";
            }
            else
            {
                Session["ReceiverType"] = 4;
               //
               // Session["isDoctorOrDentist"] = "Dentist";
            }
            if ((Request.QueryString["receiverType"] == "doctor"))
            {
                Session["DoctorType"] = "Doctor";
            }
            else if(Request.QueryString["receiverType"] == "dentist")
            {
                Session["DoctorType"] = "Dentist";
            }
            RedirectToFacePage();
        }

        localFunction lfunc = new localFunction();
        if (rbtnlDoctorType.SelectedIndex == 0) // Doctor Login
        {

            if (chkremberdoc.Checked)
            {
                lfunc.Cookie(localFunction.DOCTORCOOKIE, txtEmail.Text.Trim(), txtPass.Text.Trim(), true);
                Session["DoctorType"] = "Doctor";
                Session["isDoctorOrDentist"] = "Doctor";
            }
            else
                lfunc.Cookie(localFunction.DOCTORCOOKIE, txtEmail.Text.Trim(), txtPass.Text.Trim(), false);
            Session["isDoctorOrDentist"] = "Doctor";
            Doctor doc = new Doctor();
            lblMessage.Text = doc.DoLogin(txtEmail.Text, txtPass.Text, "");
            lblMessage.Visible = true;
        }
        else // Dentist Login
        {
            if (chkremberdoc.Checked)
            {
                lfunc.Cookie(localFunction.DENTISTCOOKIE, txtEmail.Text.Trim(), txtPass.Text.Trim(), true);
                Session["DoctorType"] = "Dentist";
                Session["isDoctorOrDentist"] = "Dentist";
            }
            else
                lfunc.Cookie(localFunction.DENTISTCOOKIE, txtEmail.Text.Trim(), txtPass.Text.Trim(), false);
            Session["isDoctorOrDentist"] = "Dentist";
            clsDentist dent = new clsDentist();
            lblMessage.Text = dent.DoDentistLogin(txtEmail.Text, txtPass.Text, "");
            lblMessage.Visible = true;
        }

       
    }

    private void RedirectToFacePage()
    {
        //Redirect the page
        string Identity = "";
        Encryption objEncription = new Encryption();

        //Identity =Request.QueryString["Id"].ToString();   at 170908  

        //Added at 180908

        if (Request.QueryString["Id"] != null)
        {
            Identity = Request.QueryString["Id"].ToString();
            //Session["userID"] = Request.QueryString["recieverId"].ToString();
            Session["DentistDoctorID"] = Identity;
            
        }
        else if (RewriteModule.RewriteContext.Current.Params["Id"] != null)
        {
            Identity = RewriteModule.RewriteContext.Current.Params["Id"].ToString();
            Session["userID"] = Identity;
        }


        //Ebd 180908

        Identity += ",2";
        Identity = objEncription.QueryStringEncode(Identity);
        if (Session["pageFromOrAction"] != null || Session["pageFromOrAction"].ToString() == "")
        {
            //Response.Redirect(Session["strHttp"] + "MessageBoard/ViewMessage.aspx?id=" + Identity);// Commented By Wahaj Nov 30 2011
            Response.Redirect(Session["strHttp"].ToString() + "Community/FacePage.aspx");//Added By Wahaj Khan Nov 30 2011
        }
    }
}
